<template>
  <ContentWrap>
    <el-form :model="queryParams" ref="queryFormRef" label-width="auto" :inline="true">
      <el-form-item label="名称" prop="name">
        <el-input v-model="queryParams.name" placeholder="请输入名称" :clearable="true" />
      </el-form-item>
      <el-form-item>
        <el-button @click="handleClickSearch">
          <Icon icon="ep:search" />
          搜索
        </el-button>
        <el-button @click="handleClickReset">
          <Icon icon="ep:refresh" />
          重置
        </el-button>
        <el-button v-hasPermi="['officeArea:class:create']" @click="handleClickCreate">
          <Icon icon="ep:plus" />
          新增
        </el-button>
      </el-form-item>
    </el-form>
    <Table
      :columns="columns"
      :page-param="queryParams"
      :adaptive="true"
      :page-data="queryData"
      save-key="officeAreaClass"
      height-per="90"
      @page-change="getPage"
      @row-dblclick="handleTableDblclick"
    >
      <template #menu="{ row }">
        <context-menu-item
          label="修改"
          @click="handleMenuUpdate(row)"
          v-hasPermi="['officeArea:class:update']"
        />
      </template>
      <template #imgUrl="{ row }">
        <span v-if="row.imgUrl == ''"></span>
        <el-image
          v-else
          preview-teleported
          loading="lazy"
          :src="row.imgUrl"
          :preview-src-list="[row.imgUrl]"
          fit="cover"
          class="w-[100px] h-[100px]"
        />
      </template>
    </Table>
  </ContentWrap>
  <OfficeAreaClassEdit ref="editFormRef" @success="getPage"
/></template>
<script setup name="officeAreaClass" lang="ts">
import OfficeAreaClassEdit from '@/views/officeArea/officeAreaClass/OfficeAreaClassEdit.vue'
import * as officeAreaClassApi from '@/api/area/officeAreaClass'
const editFormRef = ref()
const queryFormRef = ref()
const queryParams = ref({
  name: undefined
})
const queryData = ref()
const columns = [
  {
    label: '名称',
    prop: 'name'
  },
  {
    label: '图片',
    prop: 'imgUrl',
    slot: 'imgUrl'
  },
  {
    label: '创建时间',
    prop: 'createTime'
  },
  {
    label: '更新时间',
    prop: 'updateTime'
  }
]
/** 初始化 */
onMounted(() => {
  getPage()
})

/** 搜索按钮操作 */
const handleClickSearch = () => {
  getPage()
}

/** 重置按钮操作 */
const handleClickReset = () => {
  queryFormRef.value?.resetFields()
  handleClickSearch()
}

/** 新增按钮操作 */
const handleClickCreate = () => {
  editFormRef.value.open('create', 0)
}

/** 处理响应事件  */
const getPage = async () => {
  queryData.value = await officeAreaClassApi.pageQuery(queryParams.value)
}

/** 处理右击事件 修改 */
const handleMenuUpdate = (row) => {
  editFormRef.value.open('update', row.id)
}

/** 处理table行双击事件 */
const handleTableDblclick = (row) => {
  editFormRef.value.open('update', row.id)
}
</script>
